from system.object import Object
from system.eventServer import eventServer
from system.gameServer import gameServer

class EditLoop(Object):
    def __init__(self, parent, type = None, name = None):
        Object.__init__(self, parent, type, name)
        
        self.setVar("renderOp2d","sceneNode")
        self.setVar("scale",(gameServer.screenw,gameServer.screenh))
        
        eventServer.register("mouseButtonDown",self.mouseButtonDown)
        eventServer.register("mouseButtonUp",self.mouseButtonUp)
        eventServer.register("mouseMotion",self.mouseMotion)
        
        self.editLine = None
        
    def mouseButtonDown(self, cmd, args):
        if args['button'] == 1:
            self.editLine = self.addChild("line")
            self.editLine.setVar("renderOp2d","line")
            self.editLine.setVar("points",[])
            
        elif args['button'] == 2:
            self.save("lines")
        
    def mouseButtonUp(self, cmd, args):
        if args['button'] == 1:
            self.editLine = None
            
        elif args['button'] == 3:
            self.load("lines")
        
    def mouseMotion(self, cmd, args):
        if self.editLine:
            self.editLine.getVar("points").append((args['x'],args['y']))
